<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
.title{
    height: 100px;
    width: 1250px;
    margin: 0 auto;
    display: flex;
    align-items: center;
}
.title>b{
    display: inline-block;
    height: 20px;
    width: 150px;
    margin-left: 30px;
    font-size: 20px;
}
.image{
    width: 1250px;
    height: 400px;
    background-color: rgb(250, 94, 94);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-around;
}
.input{
    width: 300px;
    height: 350px;
    background-color: #fff;
    border: 1px solid #ccc;
}
.input>span{
    display: block;
    height: 45px;
    border-bottom: 1px solid #ccc;
    text-align: center;
    line-height: 45px;
    color: rgb(112, 112, 112);
}
.input>input{
    display: block;
    width: 240px;
    height: 25px;
    border: 1px solid #ccc;
    text-align: center;
    color: rgb(112, 112, 112);
    padding-left: 15px;
    margin: 20px auto;
}
#btn{
    display: block;
    width: 240px;
    height: 35px;
    border: 1px solid #ccc;
    border-radius: 5px;
    text-align: center;
    color: #fff;
    padding-left: 15px;
    margin: 40px auto;
    background-color: rgb(192, 36, 36);
}
.bottom{
    display: block;
    width: 300px;
    height: 20px;
    margin: 30px auto;
}
</style>
<body>
    <div class="title">
        <img src="./imgs/logo.png" alt="">
        <img src="./imgs/logo.png" alt="">
        <b>欢迎登录</b>
    </div>
    <div class="image">
        <img src="https://www.zhongjiu.cn/Areas/Web/Images/loginBannerImg.png" alt="">
        <div class="input">
            <span>账号登录</span>
            <input type="text" placeholder="请输入用户名" id="username">
            <input type="text" placeholder="请输入密码" id="password">
            <input type="button" value="登录" id="btn">
            <a href=""></a>
            <a href=""></a>
        </div>
    </div>
    
    <span class="bottom">Copyright © 2021   中酒网 版权所有</span>
</body>
<script src="./libs/jquery.2.2.4.js"></script>
<script>
        $("#btn").on("click",function(){
        $.ajax({
            url:"http://localhost:3001/api",
            data:{
                type:"login",
                username:$("#username").val(),
                password:$("#password").val()
            },
            success:res=>{
                console.log(res)
                res = JSON.parse(res);
                if(res.code === 0){
                    if(confirm("用户名不存在，是否跳转到注册")){
                        location.href = "./register.html"
                    }
                }else if(res.code === 1){
                    alert(res.title);
                    $("#password").val("");
                    $("#password")[0].focus();
                }else if(res.code === 2){
                    if(confirm("登录成功，是否跳转到首页")){
                        location.href = "./index.html"
                    }
                    sessionStorage.setItem("isLogin",JSON.stringify({
                        code:"OK",
                        name:res.data
                    }))
                }
            }
        })
    })
</script>
</html>